//
//  UITextView+ZKChain.m
//  ZKChain
//
//  Created by zk_01 on 2022/1/12.
//

#import "UITextView+ZKChain.h"

@implementation UITextView (ZKChain)

+ (UITextView * _Nonnull (^)(void))zk_allocInit{
    return ^{
         UITextView *v = [[UITextView alloc]init];
        return v;
    };
}

+ (UITextView * _Nonnull (^)(CGRect))zk_allocInitWithFrame{
    return ^(CGRect rect){
        UITextView * v = [[UITextView alloc]initWithFrame:rect];
        return v;
    };
}

- (UITextView * _Nonnull (^)(CGRect))zk_frame{
    return ^(CGRect rect){
        self.frame = rect;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIColor * _Nonnull))zk_backgroundColor{
    return ^(UIColor *color){
        self.backgroundColor = color;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIView * _Nonnull))zk_addToSuperView{
    return ^(UIView *view){
        [view addSubview:self];
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_userInteractionEnabled{
    return ^(BOOL isUserInteractionEnabled){
        self.userInteractionEnabled = isUserInteractionEnabled;
        return self;
    };
}

- (UITextView * _Nonnull (^)(NSInteger))zk_tag{
    return ^(NSInteger tag){
        self.tag = tag;
        return self;
    };
}

- (UITextView * _Nonnull (^)(CGRect))zk_bounds;{
    return ^(CGRect rect){
        self.bounds = rect;
        return self;
    };
}

- (UITextView * _Nonnull (^)(CGPoint))zk_center{
    return ^(CGPoint point){
        self.center = point;
        return self;
    };
}

- (UITextView * _Nonnull (^)(CGFloat))zk_alpha{
    return ^(CGFloat value){
        self.alpha = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_hidden{
    return ^(BOOL isHidden){
        self.hidden = isHidden;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIColor * _Nonnull))zk_tintColor{
    return ^(UIColor *col){
        self.tintColor = col;
        return self;
    };
}

#pragma mark UIScrollView 的
- (UITextView * _Nonnull (^)(CGPoint))zk_contentOffset{
    return ^(CGPoint offset){
        self.contentOffset = offset;
        return self;
    };
}

/// 内容大小
- (UITextView * _Nonnull (^)(CGSize))zk_contentSize{
    return ^(CGSize size){
        self.contentSize = size;
        return self;
    };
}

/// 内容边距
- (UITextView * _Nonnull (^)(UIEdgeInsets))zk_contentInset{
    return ^(UIEdgeInsets contentInset){
        self.contentInset = contentInset;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIScrollViewContentInsetAdjustmentBehavior))zk_contentInsetAdjustmentBehavior API_AVAILABLE(ios(11.0)){
    return ^(UIScrollViewContentInsetAdjustmentBehavior inset){
        self.contentInsetAdjustmentBehavior = inset;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_automaticallyAdjustsScrollIndicatorInsets API_AVAILABLE(ios(13.0)){
    return ^(BOOL isIndicatorInsets){
        self.automaticallyAdjustsScrollIndicatorInsets = isIndicatorInsets;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_bounces{
    return ^(BOOL value){
        self.bounces = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_alwaysBounceVertical{
    return ^(BOOL value){
        self.alwaysBounceVertical = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_alwaysBounceHorizontal{
    return ^(BOOL value){
        self.alwaysBounceHorizontal = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_pagingEnabled{
    return ^(BOOL value){
        self.pagingEnabled = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_scrollEnabled{
    return ^(BOOL value){
        self.scrollEnabled = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_showsVerticalScrollIndicator{
    return ^(BOOL value){
        self.showsVerticalScrollIndicator = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_showsHorizontalScrollIndicator{
    return ^(BOOL value){
        self.showsHorizontalScrollIndicator = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIScrollViewIndicatorStyle))zk_indicatorStyle{
    return ^(UIScrollViewIndicatorStyle style){
        self.indicatorStyle = style;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIEdgeInsets))zk_verticalScrollIndicatorInsets API_AVAILABLE(ios(11.1), tvos(11.1)){
    return ^(UIEdgeInsets value){
        self.verticalScrollIndicatorInsets = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIEdgeInsets))zk_horizontalScrollIndicatorInsets API_AVAILABLE(ios(11.1), tvos(11.1)){
    return ^(UIEdgeInsets value){
        self.horizontalScrollIndicatorInsets = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIEdgeInsets))zk_scrollIndicatorInsets{
    return ^(UIEdgeInsets value){
        self.scrollIndicatorInsets = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(CGFloat))zk_minimumZoomScale{
    return ^(CGFloat value){
        self.minimumZoomScale = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(CGFloat))zk_maximumZoomScale{
    return ^(CGFloat value){
        self.maximumZoomScale = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(CGFloat))zk_zoomScale{
    return ^(CGFloat value){
        self.zoomScale = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_bouncesZoom{
    return ^(BOOL value){
        self.bouncesZoom = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_scrollsToTop{
    return ^(BOOL value){
        self.scrollsToTop = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIScrollViewKeyboardDismissMode))zk_keyboardDismissMode{
    return ^(UIScrollViewKeyboardDismissMode mode){
        self.keyboardDismissMode = mode;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIRefreshControl * _Nullable))zk_refreshControl API_AVAILABLE(ios(10.0)){
    return ^(UIRefreshControl *refreshControl){
        self.refreshControl = refreshControl;
        return self;
    };
}

#pragma mark 对应UITextView 的一些属性
/// 设置代理
- (UITextView * _Nonnull (^)(id <UITextViewDelegate> _Nullable))zk_delegate{
    return ^(id <UITextViewDelegate> delagte){
        self.delegate = delagte;
        return self;
    };
}

- (UITextView * _Nonnull (^)(NSString * _Nullable))zk_text{
    return ^(NSString *text){
        self.text = text;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIFont * _Nullable))zk_font{
    return ^(UIFont *font){
        self.font = font;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIColor * _Nullable))zk_textColor{
    return ^(UIColor *color){
        self.textColor = color;
        return self;
    };
}

- (UITextView * _Nonnull (^)(NSTextAlignment))zk_textAlignment{
    return ^(NSTextAlignment aligment){
        self.textAlignment = aligment;
        return self;
    };
}

/// 当前选择的范围
- (UITextView * _Nonnull (^)(NSRange))zk_selectedRange{
    return ^(NSRange range){
        self.selectedRange = range;
        return self;
    };
}

/// 是否可编辑
- (UITextView * _Nonnull (^)(BOOL))zk_editable{
    return ^(BOOL isEditable){
        self.editable = isEditable;
        return self;
    };
}

/// 是否可选
- (UITextView * _Nonnull (^)(BOOL))zk_selectable{
    return ^(BOOL isSelectable){
        self.selectable = isSelectable;
        return self;
    };
}

/// 您可以使用这个属性指定应该在文本视图中自动转换为url的数据类型(电话号码、http链接等)。当点击时，文本视图打开负责处理URL类型的应用程序，并将URL传递给它。请注意，如果文本视图的可编辑属性设置为YES，则不会发生数据检测
- (UITextView * _Nonnull (^)(UIDataDetectorTypes))zk_dataDetectorTypes{
    return ^(UIDataDetectorTypes type){
        self.dataDetectorTypes = type;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_allowsEditingTextAttributes{
    return ^(BOOL value){
        self.allowsEditingTextAttributes = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(NSAttributedString * _Nullable))zk_attributedText{
    return ^(NSAttributedString *attributedText){
        self.attributedText = attributedText;
        return self;
    };
}

- (UITextView * _Nonnull (^)(NSDictionary<NSAttributedStringKey, id> *_Nonnull))zk_typingAttributes{
    return ^(NSDictionary<NSAttributedStringKey, id> * _Nonnull value){
        self.typingAttributes = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIView * _Nonnull))zk_inputView{
    return ^(UIView * view){
        self.inputView = view;
        return self;
    };
}

///当文本视图成为第一个响应器时要显示的自定义附件视图。
- (UITextView * _Nonnull (^)(UIView * _Nonnull))zk_inputAccessoryView{
    return ^(UIView * view){
        self.inputAccessoryView = view;
        return self;
    };
}

/// 此属性的默认值为NO。当该属性的值为YES且文本视图处于编辑模式时，选择UI将被隐藏，插入新文本将清除文本视图的内容，并将该属性的值设置回NO。
- (UITextView * _Nonnull (^)(BOOL))zk_clearsOnInsertion{
    return ^(BOOL value){
        self.clearsOnInsertion = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIEdgeInsets))zk_textContainerInset{
    return ^(UIEdgeInsets insets){
        self.textContainerInset = insets;
        return self;
    };
}

- (UITextView * _Nonnull (^)(NSDictionary<NSAttributedStringKey,id> * _Nonnull))zk_linkTextAttributes{
    return ^(NSDictionary<NSAttributedStringKey,id> * value){
        self.linkTextAttributes = value;
        return self;
    };
}

- (UITextView * _Nonnull (^)(BOOL))zk_usesStandardTextScaling API_AVAILABLE(ios(13.0)){
    return ^(BOOL value){
        self.usesStandardTextScaling = value;
        return self;
    };
}

#pragma mark 对应UITextView 的一些方法

+ (UITextView * _Nonnull (^)(CGRect,NSTextContainer * _Nullable))zk_allocInitWithFrameAndTextContainer{
    return ^(CGRect rect,NSTextContainer * _Nullable textContainer){
        UITextView * textView = [[UITextView alloc]initWithFrame:rect textContainer:textContainer];
        return textView;
    };
}

@end
